import { ImageServise } from "@/shared/api/api.image";
import { ModelServise } from "@/shared/api/api.model";
import { IImage } from "@/shared/interfaces";
import { QueryClient, useMutation, useQueries, useQuery } from "@tanstack/react-query";
import { AxiosError } from "axios";




export function useGetImageById(imageId: number) {

    const queryClient = new QueryClient

    const getImageById = useQuery<IImage, AxiosError<{ message: string }>>(
        {
            queryKey: ['images', imageId],
            queryFn: () => ImageServise.getOne(imageId),
            retry: 3,
            placeholderData: (previousData) => previousData,
        }, queryClient
    );

    const errorMessage = getImageById.error?.response?.data.message

    return {
        isSuccess: getImageById.isSuccess,
        isPending: getImageById.isPending,
        refetch: getImageById.refetch,
        errorMessage,
        image: getImageById.data
    };
}